
import json
import collections
import os, re


#============================================================================
f = open("e:\\w\\2.csv", 'r' ,encoding='utf8')
fo = open("e:\\w\\forms-noun-irregular(all).csv", 'w' ,encoding='utf8')
#fword = open("e:\\w\\verb_list.csv", 'w' ,encoding='utf8')


words = {}

for line in f.readlines():
    items=re.split("\|",line.strip())
    word                  =  items[0].strip() if len(items) >= 1 else None
    plural                =  items[1].strip() if len(items) >= 2  else ""
    

    #fword.write(word+"\n")
    if words.get(word) is None: words[word] = dict()

    form_from_book = plural
    key="plural"
    if len(form_from_book) :
        p_items =re.split(",",form_from_book)
        for pi in p_items:
            if re.search("^[a-z]+$", pi):
                pp=words[word].get(key)
                if pp is None: words[word][key] = dict()
                words[word][key][pi] = pi


for word, info in words.items():
    plural = info.get("plural") or {}
    
    if len(plural) < 1 : continue
    
    fo.write(word+"|"+"{}\n".format(",".join(p for p,v in plural.items()) ))

fo.close()

#fword.close()

